#include<bits/stdc++.h>
#define int long long
using namespace std;
int t,n,mx,mi,a[1000005],b[1000006];
bool ok;
signed main()
{
	freopen("game.in","r",stdin);
	freopen("game.out","w",stdout);
	ios::sync_with_stdio(false);
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cin>>t;
	while(t--)
	{
		ok=1;
		mi=mx=0;
		cin>>n;
		for(int i=1;i<=n;i++)
			cin>>a[i];
		for(int i=1;i<=n;i++)
			cin>>b[i];
		for(int i=1;i<=n;i++)
		{
			if(a[i]==0&&b[i]!=0)
				ok=0;
			mx=max(mx,a[i]-b[i]);
			mi=max(mi,b[i]-a[i]);
		}
		if(!ok)
			cout<<"-1\n";
		else
			cout<<mx+mi<<'\n';
	}
	return 0;
}

